<?php
//自动生成,请根据需要修改
namespace app\article\controller;
use app\common\controller\Base;
use think\facade\Request;
use think\Db;
/**
* @title 文章详情表接口
* @description 文章详情表说明
* @group 文章
*/
class Article extends Base{

	/**
	* @title 按条件删除记录
	* @description 按条件删除文章详情表的数据
	* @author 开发者（zzz）
	* @url /article/article/delete
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:content type:VarChar require:1 default:0 other: desc:文章信息 纯内容
	* @param name:content_text type:Text require:1 default:0 other: desc:文章信息 副文本
	* @param name:author type:VarChar require:1 default:0 other: desc:作者
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:status type:Int require:1 default:0 other: desc:状态值
	* @param name:create_time type:Date require:1 default:0 other: desc:创建时间
	* @param name:update_time type:Date require:1 default:0 other: desc:更新时间
	* @param name:content_picture type:VarChar require:1 default:0 other: desc:文章图片
	* @param name:title type:VarChar require:1 default:0 other: desc:文章标题
	* @param name:category_id type:VarChar require:1 default:0 other: desc:分类id
	* @param name:pick_count type:Int require:1 default:0 other: desc:点赞量
	* @param name:views_count type:Int require:1 default:0 other: desc:浏览量
	* @param name:reason type:VarChar require:1 default:0 other: desc:未通过原因
	*
	*
	* @return id:id
	* @return content:文章信息 纯内容
	* @return content_text:文章信息 副文本
	* @return author:作者
	* @return creater:创建者
	* @return updater:更新者
	* @return status:状态值
	* @return create_time:创建时间
	* @return update_time:更新时间
	* @return content_picture:文章图片
	* @return title:文章标题
	* @return category_id:分类id
	* @return pick_count:点赞量
	* @return views_count:浏览量
	* @return reason:未通过原因
	*
	*/
	public function delete (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::post('id/d');
		$input['content'] = Request::post('content');
		$input['content_text'] = Request::post('content_text');
		$input['author'] = Request::post('author');
		$input['creater'] = Request::post('creater');
		$input['updater'] = Request::post('updater');
		$input['status'] = Request::post('status/d');
		$input['create_time'] = Request::post('create_time');
		$input['update_time'] = Request::post('update_time');
		$input['content_picture'] = Request::post('content_picture');
		$input['title'] = Request::post('title');
		$input['category_id'] = Request::post('category_id');
		$input['pick_count'] = Request::post('pick_count/d');
		$input['views_count'] = Request::post('views_count/d');
		$input['reason'] = Request::post('reason');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['content'] = $input['content'];
		$msg['data']['content_text'] = $input['content_text'];
		$msg['data']['author'] = $input['author'];
		$msg['data']['creater'] = $input['creater'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['create_time'] = $input['create_time'];
		$msg['data']['update_time'] = $input['update_time'];
		$msg['data']['content_picture'] = $input['content_picture'];
		$msg['data']['title'] = $input['title'];
		$msg['data']['category_id'] = $input['category_id'];
		$msg['data']['pick_count'] = $input['pick_count'];
		$msg['data']['views_count'] = $input['views_count'];
		$msg['data']['reason'] = $input['reason'];

		// ---  模块 - 删除  ---
		//删除的条件
		$temp_map = [
			['id','=',$input['id']],
			['content','=',$input['content']],
			['content_text','=',$input['content_text']],
			['author','=',$input['author']],
			['creater','=',$input['creater']],
			['updater','=',$input['updater']],
			['status','=',$input['status']],
			['create_time','=',$input['create_time']],
			['update_time','=',$input['update_time']],
			['content_picture','=',$input['content_picture']],
			['title','=',$input['title']],
			['category_id','=',$input['category_id']],
			['pick_count','=',$input['pick_count']],
			['views_count','=',$input['views_count']],
			['reason','=',$input['reason']],
		];
		$delete_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2] == null || $v[2] == ''){
				continue;
			}
			array_push($delete_map,$v);
		}
		if(empty($delete_map)){
			$msg['msg'] = '删除条件不能为空';
			return $this->errorJson($msg);
		}

		//删除数据
		$delete_res = Db::name('Article')->where($delete_map)->delete();
		if(!$delete_res){
			$msg['msg'] = '删除数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $delete_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取单条数据
	* @description 根据ID获取文章详情表的指定记录
	* @author 开发者（zzz）
	* @url /article/article/info
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	*
	*
	* @return id:id
	*
	*/
	public function info (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::param('id/d');

		// input结果返回
		$msg['data']['id'] = $input['id'];

		//模块 - 验证器
		$articleValidate = new \app\article\validate\Article;
		$validate = $articleValidate->scene('only_id')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $articleValidate->getError();
			return $this->errorJson($msg);
		}

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
		];
		//去除为空的条件
		$find_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($find_map,$v);
		}

		//获取数据
		$select_res = Db::name('Article')->where($find_map)->find();
        if($select_res!=null){//查看详情时，浏览量+1
            $views =   $select_res['views_count']+1;
            $select_res['views_count'] =  $views;
            Db::name('Article')->where($find_map)->update($select_res);
        }

		// find 返回数据
		$msg['data'] = $select_res;

		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 更新记录
	* @description 根据ID更新文章详情表指定记录的数据
	* @author 开发者（zzz）
	* @url /article/article/edit
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:content type:VarChar require:1 default:0 other: desc:文章信息 纯内容
	* @param name:content_text type:Text require:1 default:0 other: desc:文章信息 副文本
	* @param name:author type:VarChar require:1 default:0 other: desc:作者
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:status type:Int require:1 default:0 other: desc:状态值
	* @param name:create_time type:Date require:1 default:0 other: desc:创建时间
	* @param name:update_time type:Date require:1 default:0 other: desc:更新时间
	* @param name:content_picture type:VarChar require:1 default:0 other: desc:文章图片
	* @param name:title type:VarChar require:1 default:0 other: desc:文章标题
	* @param name:category_id type:VarChar require:1 default:0 other: desc:分类id
	* @param name:pick_count type:Int require:1 default:0 other: desc:点赞量
	* @param name:views_count type:Int require:1 default:0 other: desc:浏览量
	* @param name:reason type:VarChar require:1 default:0 other: desc:未通过原因
	*
	*
	* @return id:id
	* @return content:文章信息 纯内容
	* @return content_text:文章信息 副文本
	* @return author:作者
	* @return creater:创建者
	* @return updater:更新者
	* @return status:状态值
	* @return create_time:创建时间
	* @return update_time:更新时间
	* @return content_picture:文章图片
	* @return title:文章标题
	* @return category_id:分类id
	* @return pick_count:点赞量
	* @return views_count:浏览量
	* @return reason:未通过原因
	*
	*/
	public function edit (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::post('id/d');
		$input['content'] = Request::post('content');
		$input['content_text'] = Request::post('content_text');
		$input['author'] = Request::post('author');
		$input['creater'] = Request::post('creater');
		$input['updater'] = Request::post('updater');
		$input['status'] = '2';
		$input['create_time'] = Request::post('create_time');
		$input['update_time'] = date("Y-m-d H:i:s");
		$input['content_picture'] = Request::post('content_picture');
		$input['title'] = Request::post('title');
		$input['category_id'] = Request::post('category_id');
		$input['pick_count'] = Request::post('pick_count/d');
		$input['views_count'] = Request::post('views_count/d');
		$input['reason'] = '';

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['content'] = $input['content'];
		$msg['data']['content_text'] = $input['content_text'];
		$msg['data']['author'] = $input['author'];
		$msg['data']['creater'] = $input['creater'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['create_time'] = $input['create_time'];
		$msg['data']['update_time'] = $input['update_time'];
		$msg['data']['content_picture'] = $input['content_picture'];
		$msg['data']['title'] = $input['title'];
		$msg['data']['category_id'] = $input['category_id'];
		$msg['data']['pick_count'] = $input['pick_count'];
		$msg['data']['views_count'] = $input['views_count'];
		$msg['data']['reason'] = $input['reason'];

		//模块 - 验证器
		$articleValidate = new \app\article\validate\Article;
		$validate = $articleValidate->scene('update')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $articleValidate->getError();
			return $this->errorJson($msg);
		}

        $user =  getIdByToken($input['token']);//通过token获取用户id
        if ($user ===''){ //无法获取的话就是前台用户 需要审核
        }else{
            if(count($user->all())>0){//判断是否有数据返回
                $role =   getRoleByid($user->all()['0']['account_id']);//通过用户id去查询 去获取该成员角色
                if($role->all()['0']['role'] == 'admin'){ //如果是管理员 无须审核 直接为成功状态
                    $input['status']  = '1';
                }
            }
            $input['updater'] = $user->all()['0']['account_id'];
        }

		// ---	模块 - 修改  ---
		//更新的条件
		$update_date = [
		'id'=>$input['id'],
		];
		//更新的数据
		$update_map = [
			'content'=>$input['content'],
			'content_text'=>$input['content_text'],
			'author'=>$input['author'],
			'updater'=>$input['updater'],
			'status'=>$input['status'],
			'update_time'=>$input['update_time'],
			'content_picture'=>$input['content_picture'],
			'title'=>$input['title'],
			'category_id'=>$input['category_id'],
			'pick_count'=>$input['pick_count'],
			'views_count'=>$input['views_count'],
			'reason'=>$input['reason'],
		];
		//获取数据
		$update_res = Db::name('Article')->where($update_date)->update($update_map);
		if(!$update_res){
			$msg['msg'] = '更新据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $update_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（paginate）
	* @description 获取文章详情表的列表数据（分页）
	* @author 开发者（zzz）
	* @url /article/article/get_list
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:content type:VarChar require:1 default:0 other: desc:文章信息 纯内容
	* @param name:content_text type:Text require:1 default:0 other: desc:文章信息 副文本
	* @param name:author type:VarChar require:1 default:0 other: desc:作者
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:status type:Int require:1 default:0 other: desc:状态值
	* @param name:create_time type:Date require:1 default:0 other: desc:创建时间
	* @param name:update_time type:Date require:1 default:0 other: desc:更新时间
	* @param name:content_picture type:VarChar require:1 default:0 other: desc:文章图片
	* @param name:title type:VarChar require:1 default:0 other: desc:文章标题
	* @param name:category_id type:VarChar require:1 default:0 other: desc:分类id
	* @param name:pick_count type:Int require:1 default:0 other: desc:点赞量
	* @param name:views_count type:Int require:1 default:0 other: desc:浏览量
	* @param name:reason type:VarChar require:1 default:0 other: desc:未通过原因
	*
	* @param name:page type:Int require:0 default:0 other: desc:当前页
	* @param name:pagesize type:Int require:0 default:0 other: desc:每页数量
	*
	* @return id:id
	* @return content:文章信息 纯内容
	* @return content_text:文章信息 副文本
	* @return author:作者
	* @return creater:创建者
	* @return updater:更新者
	* @return status:状态值
	* @return create_time:创建时间
	* @return update_time:更新时间
	* @return content_picture:文章图片
	* @return title:文章标题
	* @return category_id:分类id
	* @return pick_count:点赞量
	* @return views_count:浏览量
	* @return reason:未通过原因
	*
	*/
	public function get_list (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::param('id/d');
		$input['content'] = Request::param('content');
		$input['content_text'] = Request::param('content_text');
		$input['author'] = Request::param('author');
		$input['creater'] = Request::param('creater');
		$input['updater'] = Request::param('updater');
		$input['status'] = Request::param('status/d');
		$input['create_time'] = Request::param('create_time');
		$input['update_time'] = Request::param('update_time');
		$input['content_picture'] = Request::param('content_picture');
		$input['title'] = Request::param('title');
		$input['category_id'] = Request::param('category_id');
		$input['pick_count'] = Request::param('pick_count/d');
		$input['views_count'] = Request::param('views_count/d');
		$input['reason'] = Request::param('reason');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['content'] = $input['content'];
		$msg['data']['content_text'] = $input['content_text'];
		$msg['data']['author'] = $input['author'];
		$msg['data']['creater'] = $input['creater'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['create_time'] = $input['create_time'];
		$msg['data']['update_time'] = $input['update_time'];
		$msg['data']['content_picture'] = $input['content_picture'];
		$msg['data']['title'] = $input['title'];
		$msg['data']['category_id'] = $input['category_id'];
		$msg['data']['pick_count'] = $input['pick_count'];
		$msg['data']['views_count'] = $input['views_count'];
		$msg['data']['reason'] = $input['reason'];

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
			['content','like','%'.$input['content'].'%'],
			['content_text','like','%'.$input['content_text'].'%'],
			['author','like','%'.$input['author'].'%'],
			['creater','like','%'.$input['creater'].'%'],
			['updater','like','%'.$input['updater'].'%'],
			['status','=',$input['status']],
			['create_time','=',$input['create_time']],
			['update_time','=',$input['update_time']],
			['content_picture','like','%'.$input['content_picture'].'%'],
			['title','like','%'.$input['title'].'%'],
			['category_id','like','%'.$input['category_id'].'%'],
			['pick_count','=',$input['pick_count']],
			['views_count','=',$input['views_count']],
			['reason','like','%'.$input['reason'].'%'],
		];
		//去除为空的条件
		$paginate_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($paginate_map,$v);
		}

		//获取数据
		$select_res = Db::name('Article')->where($paginate_map)->order('create_time','desc')->paginate();
        $select_res=Db::name('Article a')
            ->field('a.*,b.nickname,b.class_name')
            ->leftjoin('category b','a.category_id=b.id')
            ->where($paginate_map)
            ->order('a.create_time','desc')
            ->paginate();


		// paginate 返回数据
		$msg['list'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 获取列表数据（select）
	* @description 获取文章详情表的列表数据（无分页）
	* @author 开发者（zzz）
	* @url /article/article/get_select
	* @method *
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:id type:Int require:1 default:0 other: desc:id
	* @param name:content type:VarChar require:1 default:0 other: desc:文章信息 纯内容
	* @param name:content_text type:Text require:1 default:0 other: desc:文章信息 副文本
	* @param name:author type:VarChar require:1 default:0 other: desc:作者
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:status type:Int require:1 default:0 other: desc:状态值
	* @param name:create_time type:Date require:1 default:0 other: desc:创建时间
	* @param name:update_time type:Date require:1 default:0 other: desc:更新时间
	* @param name:content_picture type:VarChar require:1 default:0 other: desc:文章图片
	* @param name:title type:VarChar require:1 default:0 other: desc:文章标题
	* @param name:category_id type:VarChar require:1 default:0 other: desc:分类id
	* @param name:pick_count type:Int require:1 default:0 other: desc:点赞量
	* @param name:views_count type:Int require:1 default:0 other: desc:浏览量
	* @param name:reason type:VarChar require:1 default:0 other: desc:未通过原因
	*
	*
	* @return id:id
	* @return content:文章信息 纯内容
	* @return content_text:文章信息 副文本
	* @return author:作者
	* @return creater:创建者
	* @return updater:更新者
	* @return status:状态值
	* @return create_time:创建时间
	* @return update_time:更新时间
	* @return content_picture:文章图片
	* @return title:文章标题
	* @return category_id:分类id
	* @return pick_count:点赞量
	* @return views_count:浏览量
	* @return reason:未通过原因
	*
	*/
	public function get_select (){
		$input=input();
		//模块 - 输入数据
		$input['id'] = Request::param('id/d');
		$input['content'] = Request::param('content');
		$input['content_text'] = Request::param('content_text');
		$input['author'] = Request::param('author');
		$input['creater'] = Request::param('creater');
		$input['updater'] = Request::param('updater');
		$input['status'] = Request::param('status/d');
		$input['create_time'] = Request::param('create_time');
		$input['update_time'] = Request::param('update_time');
		$input['content_picture'] = Request::param('content_picture');
		$input['title'] = Request::param('title');
		$input['category_id'] = Request::param('category_id');
		$input['pick_count'] = Request::param('pick_count/d');
		$input['views_count'] = Request::param('views_count/d');
		$input['reason'] = Request::param('reason');

		// input结果返回
		$msg['data']['id'] = $input['id'];
		$msg['data']['content'] = $input['content'];
		$msg['data']['content_text'] = $input['content_text'];
		$msg['data']['author'] = $input['author'];
		$msg['data']['creater'] = $input['creater'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['create_time'] = $input['create_time'];
		$msg['data']['update_time'] = $input['update_time'];
		$msg['data']['content_picture'] = $input['content_picture'];
		$msg['data']['title'] = $input['title'];
		$msg['data']['category_id'] = $input['category_id'];
		$msg['data']['pick_count'] = $input['pick_count'];
		$msg['data']['views_count'] = $input['views_count'];
		$msg['data']['reason'] = $input['reason'];

		// ---	模块 - 查询  ---
		//查询条件
		$temp_map = [
			['id','=',$input['id']],
			['content','like','%'.$input['content'].'%'],
			['content_text','like','%'.$input['content_text'].'%'],
			['author','like','%'.$input['author'].'%'],
			['creater','like','%'.$input['creater'].'%'],
			['updater','like','%'.$input['updater'].'%'],
			['status','=',$input['status']],
			['create_time','=',$input['create_time']],
			['update_time','=',$input['update_time']],
			['content_picture','like','%'.$input['content_picture'].'%'],
			['title','like','%'.$input['title'].'%'],
			['category_id','like','%'.$input['category_id'].'%'],
			['pick_count','=',$input['pick_count']],
			['views_count','=',$input['views_count']],
			['reason','like','%'.$input['reason'].'%'],
		];
		//去除为空的条件
		$select_map = [];
		foreach ($temp_map as $k=>$v){
			if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
				continue;
			}
			array_push($select_map,$v);
		}

		//获取数据
		$select_res = Db::name('Article')->where($select_map)->select();

		// select 返回数据
		$msg['list'] = $select_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}
	/**
	* @title 插入记录
	* @description 插入文章详情表数据
	* @author 开发者（zzz）
	* @url /article/article/add
	* @method post
	*
	* @param name:token require:1 default: desc:token
	*
	* @param name:content type:VarChar require:1 default:0 other: desc:文章信息 纯内容
	* @param name:content_text type:Text require:1 default:0 other: desc:文章信息 副文本
	* @param name:author type:VarChar require:1 default:0 other: desc:作者
	* @param name:creater type:VarChar require:1 default:0 other: desc:创建者
	* @param name:updater type:VarChar require:1 default:0 other: desc:更新者
	* @param name:status type:Int require:1 default:0 other: desc:状态值
	* @param name:create_time type:Date require:1 default:0 other: desc:创建时间
	* @param name:update_time type:Date require:1 default:0 other: desc:更新时间
	* @param name:content_picture type:VarChar require:1 default:0 other: desc:文章图片
	* @param name:title type:VarChar require:1 default:0 other: desc:文章标题
	* @param name:category_id type:VarChar require:1 default:0 other: desc:分类id
	* @param name:pick_count type:Int require:1 default:0 other: desc:点赞量
	* @param name:views_count type:Int require:1 default:0 other: desc:浏览量
	* @param name:reason type:VarChar require:1 default:0 other: desc:未通过原因
	*
	*
	* @return content:文章信息 纯内容
	* @return content_text:文章信息 副文本
	* @return author:作者
	* @return creater:创建者
	* @return updater:更新者
	* @return status:状态值
	* @return create_time:创建时间
	* @return update_time:更新时间
	* @return content_picture:文章图片
	* @return title:文章标题
	* @return category_id:分类id
	* @return pick_count:点赞量
	* @return views_count:浏览量
	* @return reason:未通过原因
	*
	*/
	public function add (){
		$input=input();
		//模块 - 输入数据
		$input['content'] = Request::post('content');
		$input['content_text'] = Request::post('content_text');
		$input['author'] = Request::post('author');
		$input['creater'] = Request::post('creater');
		$input['updater'] = Request::post('updater');
		$input['status'] = '2';//默认为需要审核;
		$input['create_time'] = date("Y-m-d H:i:s");
		$input['update_time'] = date("Y-m-d H:i:s");
		$input['content_picture'] = Request::post('content_picture');
		$input['title'] = Request::post('title');
		$input['category_id'] = Request::post('category_id');
		$input['pick_count'] = '0';
		$input['views_count'] = '0';
		$input['reason'] = Request::post('reason');

		// input结果返回
		$msg['data']['content'] = $input['content'];
		$msg['data']['content_text'] = $input['content_text'];
		$msg['data']['author'] = $input['author'];
		$msg['data']['creater'] = $input['creater'];
		$msg['data']['updater'] = $input['updater'];
		$msg['data']['status'] = $input['status'];
		$msg['data']['create_time'] = $input['create_time'];
		$msg['data']['update_time'] = $input['update_time'];
		$msg['data']['content_picture'] = $input['content_picture'];
		$msg['data']['title'] = $input['title'];
		$msg['data']['category_id'] = $input['category_id'];
		$msg['data']['pick_count'] = $input['pick_count'];
		$msg['data']['views_count'] = $input['views_count'];
		$msg['data']['reason'] = $input['reason'];

		//模块 - 验证器
		$articleValidate = new \app\article\validate\Article;
		$validate = $articleValidate->scene('add')->check($input);
		if (!$validate) {
			$msg['msg'] = '验证失败';
			$msg['validate'] = $articleValidate->getError();
			return $this->errorJson($msg);
		}

        $user =  getIdByToken($input['token']);//通过token获取用户id
        if ($user ===''){ //无法获取的话就是前台用户 需要审核
        }else{
            if(count($user->all())>0){//判断是否有数据返回
                $role =   getRoleByid($user->all()['0']['account_id']);//通过用户id去查询 去获取该成员角色
                if($role->all()['0']['role'] == 'admin'){ //如果是管理员 无须审核 直接为成功状态
                    $input['status']  = '1';
                }
            }
            $msg['data']['creater'] =  $input['creater'] = $user->all()['0']['account_id'];
            $msg['data']['updater'] =  $input['updater'] = $user->all()['0']['account_id'];
        }

		// ---	模块 - 新增  ---
		//插入的数据
		$insert_data = [
			'content'=>$input['content'],
			'content_text'=>$input['content_text'],
			'author'=>$input['author'],
			'creater'=>$input['creater'],
			'updater'=>$input['updater'],
			'status'=>$input['status'],
			'create_time'=>$input['create_time'],
			'update_time'=>$input['update_time'],
			'content_picture'=>$input['content_picture'],
			'title'=>$input['title'],
			'category_id'=>$input['category_id'],
			'pick_count'=>$input['pick_count'],
			'views_count'=>$input['views_count'],
			'reason'=>$input['reason'],
		];
		//添加数据
		$insert_res = Db::name('Article')->data($insert_data)->insert();
		if(!$insert_res){
			$msg['msg'] = '插入数据失败！';
			return $this->errorJson($msg);
		}
		$msg['res'] = $insert_res;


		//接口输出json数据
		$msg['msg'] = '操作成功！';
		return $this->successJson($msg);
	}

    /**
     * @title 文章不通过接口
     * @description 修改文章为审核不通过状态
     * @author 开发者（zzz）
     * @url /article/article/notPass
     * @method post
     *
     * @param name:token require:1 default: desc:token
     *
     * @param name:id type:Int require:1 default:0 other: desc:id
     * @param name:reason type:VarChar require:1 default:0 other: desc:未通过原因
     *
     *
     * @return id:id
     * @return reason:未通过原因
     *
     */
    public function notPass (){
        $input=input();
        //模块 - 输入数据
        $input['id'] = Request::post('id/d');
        $input['status'] = '3';//不通过
        $input['reason'] = Request::post('reason');
        $input['update_time'] = date("Y-m-d H:i:s");

        // input结果返回
        $msg['data']['id'] = $input['id'];
        $msg['data']['updater'] = $input['updater'];
        $msg['data']['status'] = $input['status'];
        $msg['data']['update_time'] = $input['update_time'];
        $msg['data']['reason'] = $input['reason'];

        //模块 - 验证器
        $articleValidate = new \app\article\validate\Article;
        $validate = $articleValidate->scene('only_id')->check($input);
        if (!$validate) {
            $msg['msg'] = '验证失败';
            $msg['validate'] = $articleValidate->getError();
            return $this->errorJson($msg);
        }

        $user =  getIdByToken($input['token']);//通过token获取用户id
        if(count($user->all())>0){
            $msg['data']['updater']  = $input['updater'] = $user->all()['0']['account_id'];
        }

        // ---	模块 - 修改  ---
        //更新的条件
        $update_date = [
            'id'=>$input['id'],
        ];
        //更新的数据
        $update_map = [
            'updater'=>$input['updater'],
            'status'=>$input['status'],
            'update_time'=>$input['update_time'],
            'reason'=>$input['reason'],
        ];
        //获取数据
        $update_res = Db::name('Article')->where($update_date)->update($update_map);
        if(!$update_res){
            $msg['msg'] = '更新据失败！';
            return $this->errorJson($msg);
        }
        $msg['res'] = $update_res;


        //接口输出json数据
        $msg['msg'] = '操作成功！';
        return $this->successJson($msg);
    }

    /**
     * @title 文章通过接口
     * @description 修改文章为审核通过状态
     * @author 开发者（zzz）
     * @url /article/article/pass
     * @method post
     *
     * @param name:token require:1 default: desc:token
     *
     * @param name:id type:Int require:1 default:0 other: desc:id
     * @param name:reason type:VarChar require:1 default:0 other: desc:未通过原因
     *
     *
     * @return id:id
     *
     *
     */
    public function pass (){
        $input=input();
        //模块 - 输入数据
        $input['id'] = Request::post('id/d');
        $input['status'] = '1';//不通过
        $input['update_time'] = date("Y-m-d H:i:s");

        // input结果返回
        $msg['data']['id'] = $input['id'];
        $msg['data']['updater'] = $input['updater'];
        $msg['data']['status'] = $input['status'];
        $msg['data']['update_time'] = $input['update_time'];

        //模块 - 验证器
        $articleValidate = new \app\article\validate\Article;
        $validate = $articleValidate->scene('only_id')->check($input);
        if (!$validate) {
            $msg['msg'] = '验证失败';
            $msg['validate'] = $articleValidate->getError();
            return $this->errorJson($msg);
        }

        $user =  getIdByToken($input['token']);//通过token获取用户id
        if(count($user->all())>0){
            $msg['data']['updater']  = $input['updater'] = $user->all()['0']['account_id'];
        }


        // ---	模块 - 修改  ---
        //更新的条件
        $update_date = [
            'id'=>$input['id'],
        ];
        //更新的数据
        $update_map = [
            'updater'=>$input['updater'],
            'status'=>$input['status'],
            'update_time'=>$input['update_time'],
        ];
        //获取数据
        $update_res = Db::name('Article')->where($update_date)->update($update_map);
        if(!$update_res){
            $msg['msg'] = '更新据失败！';
            return $this->errorJson($msg);
        }
        $msg['res'] = $update_res;


        //接口输出json数据
        $msg['msg'] = '操作成功！';
        return $this->successJson($msg);
    }
    /**
     * @title 获取列表数据（paginate）
     * @description 获取仅通过文章详情表的列表数据（分页）
     * @author 开发者（zzz）
     * @url /article/article/get_success_list
     * @method *
     *
     * @param name:token require:1 default: desc:token
     *
     * @param name:id type:Int require:1 default:0 other: desc:id
     * @param name:content type:VarChar require:1 default:0 other: desc:文章信息 纯内容
     * @param name:content_text type:Text require:1 default:0 other: desc:文章信息 副文本
     * @param name:author type:VarChar require:1 default:0 other: desc:作者
     * @param name:creater type:VarChar require:1 default:0 other: desc:创建者
     * @param name:updater type:VarChar require:1 default:0 other: desc:更新者
     * @param name:status type:Int require:1 default:0 other: desc:状态值
     * @param name:create_time type:Date require:1 default:0 other: desc:创建时间
     * @param name:update_time type:Date require:1 default:0 other: desc:更新时间
     * @param name:content_picture type:VarChar require:1 default:0 other: desc:文章图片
     * @param name:title type:VarChar require:1 default:0 other: desc:文章标题
     * @param name:category_id type:VarChar require:1 default:0 other: desc:分类id
     * @param name:pick_count type:Int require:1 default:0 other: desc:点赞量
     * @param name:views_count type:Int require:1 default:0 other: desc:浏览量
     * @param name:reason type:VarChar require:1 default:0 other: desc:未通过原因
     *
     * @param name:page type:Int require:0 default:0 other: desc:当前页
     * @param name:pagesize type:Int require:0 default:0 other: desc:每页数量
     *
     * @return id:id
     * @return content:文章信息 纯内容
     * @return content_text:文章信息 副文本
     * @return author:作者
     * @return creater:创建者
     * @return updater:更新者
     * @return status:状态值
     * @return create_time:创建时间
     * @return update_time:更新时间
     * @return content_picture:文章图片
     * @return title:文章标题
     * @return category_id:分类id
     * @return pick_count:点赞量
     * @return views_count:浏览量
     * @return reason:未通过原因
     *
     */
    public function get_success_list (){
        $input=input();
        //模块 - 输入数据
        $input['id'] = Request::param('id/d');
        $input['content'] = Request::param('content');
        $input['content_text'] = Request::param('content_text');
        $input['author'] = Request::param('author');
        $input['creater'] = Request::param('creater');
        $input['updater'] = Request::param('updater');
        $input['status'] = Request::param('status/d');
        $input['create_time'] = Request::param('create_time');
        $input['update_time'] = Request::param('update_time');
        $input['content_picture'] = Request::param('content_picture');
        $input['title'] = Request::param('title');
        $input['category_id'] = Request::param('category_id');
        $input['pick_count'] = Request::param('pick_count/d');
        $input['views_count'] = Request::param('views_count/d');
        $input['reason'] = Request::param('reason');

        // input结果返回
        $msg['data']['id'] = $input['id'];
        $msg['data']['content'] = $input['content'];
        $msg['data']['content_text'] = $input['content_text'];
        $msg['data']['author'] = $input['author'];
        $msg['data']['creater'] = $input['creater'];
        $msg['data']['updater'] = $input['updater'];
        $msg['data']['status'] = $input['status'];
        $msg['data']['create_time'] = $input['create_time'];
        $msg['data']['update_time'] = $input['update_time'];
        $msg['data']['content_picture'] = $input['content_picture'];
        $msg['data']['title'] = $input['title'];
        $msg['data']['category_id'] = $input['category_id'];
        $msg['data']['pick_count'] = $input['pick_count'];
        $msg['data']['views_count'] = $input['views_count'];
        $msg['data']['reason'] = $input['reason'];

        // ---	模块 - 查询  ---
        //查询条件
        $temp_map = [
            ['id','=',$input['id']],
            ['content','like','%'.$input['content'].'%'],
            ['content_text','like','%'.$input['content_text'].'%'],
            ['author','like','%'.$input['author'].'%'],
            ['creater','like','%'.$input['creater'].'%'],
            ['updater','like','%'.$input['updater'].'%'],
            ['status','=','1'],
            ['create_time','=',$input['create_time']],
            ['update_time','=',$input['update_time']],
            ['content_picture','like','%'.$input['content_picture'].'%'],
            ['title','like','%'.$input['title'].'%'],
            ['category_id','like','%'.$input['category_id'].'%'],
            ['pick_count','=',$input['pick_count']],
            ['views_count','=',$input['views_count']],
            ['reason','like','%'.$input['reason'].'%'],
        ];
        //去除为空的条件
        $paginate_map = [];
        foreach ($temp_map as $k=>$v){
            if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
                continue;
            }
            array_push($paginate_map,$v);
        }

        //获取数据
        $select_res = Db::name('Article')->where($paginate_map)->paginate();

        // paginate 返回数据
        $msg['list'] = $select_res;


        //接口输出json数据
        $msg['msg'] = '操作成功！';
        return $this->successJson($msg);
    }
    /**
     * @title 获取列表数据（paginate）
     * @description 获取文章详情表的列表数据仅我的（分页）
     * @author 开发者（zzz）
     * @url /article/article/get_my_list
     * @method *
     *
     * @param name:token require:1 default: desc:token
     *
     * @param name:id type:Int require:1 default:0 other: desc:id
     * @param name:content type:VarChar require:1 default:0 other: desc:文章信息 纯内容
     * @param name:content_text type:Text require:1 default:0 other: desc:文章信息 副文本
     * @param name:author type:VarChar require:1 default:0 other: desc:作者
     * @param name:creater type:VarChar require:1 default:0 other: desc:创建者
     * @param name:updater type:VarChar require:1 default:0 other: desc:更新者
     * @param name:status type:Int require:1 default:0 other: desc:状态值
     * @param name:create_time type:Date require:1 default:0 other: desc:创建时间
     * @param name:update_time type:Date require:1 default:0 other: desc:更新时间
     * @param name:content_picture type:VarChar require:1 default:0 other: desc:文章图片
     * @param name:title type:VarChar require:1 default:0 other: desc:文章标题
     * @param name:category_id type:VarChar require:1 default:0 other: desc:分类id
     * @param name:pick_count type:Int require:1 default:0 other: desc:点赞量
     * @param name:views_count type:Int require:1 default:0 other: desc:浏览量
     * @param name:reason type:VarChar require:1 default:0 other: desc:未通过原因
     *
     * @param name:page type:Int require:0 default:0 other: desc:当前页
     * @param name:pagesize type:Int require:0 default:0 other: desc:每页数量
     *
     * @return id:id
     * @return content:文章信息 纯内容
     * @return content_text:文章信息 副文本
     * @return author:作者
     * @return creater:创建者
     * @return updater:更新者
     * @return status:状态值
     * @return create_time:创建时间
     * @return update_time:更新时间
     * @return content_picture:文章图片
     * @return title:文章标题
     * @return category_id:分类id
     * @return pick_count:点赞量
     * @return views_count:浏览量
     * @return reason:未通过原因
     *
     */
    public function get_my_list (){
        $input=input();
        //模块 - 输入数据
        $input['id'] = Request::param('id/d');
        $input['content'] = Request::param('content');
        $input['content_text'] = Request::param('content_text');
        $input['author'] = Request::param('author');
        $input['creater'] = Request::param('creater');
        $input['updater'] = Request::param('updater');
        $input['status'] = Request::param('status/d');
        $input['create_time'] = Request::param('create_time');
        $input['update_time'] = Request::param('update_time');
        $input['content_picture'] = Request::param('content_picture');
        $input['title'] = Request::param('title');
        $input['category_id'] = Request::param('category_id');
        $input['pick_count'] = Request::param('pick_count/d');
        $input['views_count'] = Request::param('views_count/d');
        $input['reason'] = Request::param('reason');

        // input结果返回
        $msg['data']['id'] = $input['id'];
        $msg['data']['content'] = $input['content'];
        $msg['data']['content_text'] = $input['content_text'];
        $msg['data']['author'] = $input['author'];
        $msg['data']['creater'] = $input['creater'];
        $msg['data']['updater'] = $input['updater'];
        $msg['data']['status'] = $input['status'];
        $msg['data']['create_time'] = $input['create_time'];
        $msg['data']['update_time'] = $input['update_time'];
        $msg['data']['content_picture'] = $input['content_picture'];
        $msg['data']['title'] = $input['title'];
        $msg['data']['category_id'] = $input['category_id'];
        $msg['data']['pick_count'] = $input['pick_count'];
        $msg['data']['views_count'] = $input['views_count'];
        $msg['data']['reason'] = $input['reason'];

        $user =  getIdByToken($input['token']);//通过token获取用户id
        if(count($user->all())>0){
            $msg['data']['creater']  = $input['creater'] = $user->all()['0']['account_id'];
            $msg['data']['updater']  = $input['updater'] = $user->all()['0']['account_id'];
        }else{
            $msg['msg'] = '无法获取用户数据！';
            return $this->errorJson($msg);
        }

        // ---	模块 - 查询  ---
        //查询条件
        $temp_map = [
            ['id','=',$input['id']],
            ['content','like','%'.$input['content'].'%'],
            ['content_text','like','%'.$input['content_text'].'%'],
            ['author','like','%'.$input['author'].'%'],
            ['creater','=',$input['creater']],
            ['updater','like','%'.$input['updater'].'%'],
            ['status','=',$input['status']],
            ['create_time','=',$input['create_time']],
            ['update_time','=',$input['update_time']],
            ['content_picture','like','%'.$input['content_picture'].'%'],
            ['title','like','%'.$input['title'].'%'],
            ['category_id','like','%'.$input['category_id'].'%'],
            ['pick_count','=',$input['pick_count']],
            ['views_count','=',$input['views_count']],
            ['reason','like','%'.$input['reason'].'%'],
        ];
        //去除为空的条件
        $paginate_map = [];
        foreach ($temp_map as $k=>$v){
            if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
                continue;
            }
            array_push($paginate_map,$v);
        }

        //获取数据
        $select_res = Db::name('Article')->where($paginate_map)->paginate();

        // paginate 返回数据
        $msg['list'] = $select_res;


        //接口输出json数据
        $msg['msg'] = '操作成功！';
        return $this->successJson($msg);
    }

    /**
     * @title 点赞
     * @description 根据ID获取文章详情表的指定记录并加1点赞数
     * @author 开发者（zzz）
     * @url /article/article/pickAdd
     * @method *
     *
     * @param name:token require:1 default: desc:token
     *
     * @param name:id type:Int require:1 default:0 other: desc:id
     *
     *
     * @return id:id
     *
     */
    public function pickAdd (){
        $input=input();
        //模块 - 输入数据
        $input['id'] = Request::param('id/d');

        // input结果返回
        $msg['data']['id'] = $input['id'];

        //模块 - 验证器
        $articleValidate = new \app\article\validate\Article;
        $validate = $articleValidate->scene('only_id')->check($input);
        if (!$validate) {
            $msg['msg'] = '验证失败';
            $msg['validate'] = $articleValidate->getError();
            return $this->errorJson($msg);
        }

        $user =  getIdByToken($input['token']);//通过token获取用户id
        if(count($user->all())>0){
            $msg['data']['creater']  = $input['creater'] = $user->all()['0']['account_id'];
            $msg['data']['updater']  = $input['updater'] = $user->all()['0']['account_id'];
        }else{
            $msg['msg'] = '无法获取用户数据！';
            return $this->errorJson($msg);
        }

        // ---	模块 - 查询  ---
        //查询条件
        $temp_map = [
            ['id','=',$input['id']],
        ];
        //去除为空的条件
        $find_map = [];
        foreach ($temp_map as $k=>$v){
            if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
                continue;
            }
            array_push($find_map,$v);
        }

        //获取数据
        $select_res = Db::name('Article')->where($find_map)->find();
        if($select_res!=null){
            $pick_map = [
                ['article_id','=',$input['id']],
                ['creater','=',$input['creater']],
                ['status','=',1]
            ];
            $pick_result = Db::name('pick')->where($pick_map)->find();//根据用户id和创建者
            if($pick_result==null) { //如果数据已存在代表已点赞，结束操作
                $views = $select_res['pick_count'] + 1;
                $select_res['pick_count'] = $views;
                $result = Db::name('Article')->where($find_map)->update($select_res);
                if ($result > 0) {//点赞成功后记录，避免同一用户多次点赞
                    $insert_data = [
                        'article_id' => $input['id'],
                        'create_time' => date("Y-m-d H:i:s"),
                        'creater' => $input['creater'],
                        'update_time' => date("Y-m-d H:i:s"),
                        'updater' => $input['updater'],
                        'status' => '1',
                        'ext1' => $input['ext1'],
                    ];
                    //添加数据
                    $insert_res = Db::name('pick')->data($insert_data)->insert();
                }
            }else{
                $msg['msg'] = '您已点赞，请勿重复操作！';
                return $this->errorJson($msg);
            }
        }
        // find 返回数据
        $msg['data'] = $select_res;


        //接口输出json数据
        $msg['msg'] = '操作成功！';
        return $this->successJson($msg);
    }
    /**
     * @title 取消点赞
     * @description 根据ID获取文章详情表的指定记录并减1点赞数
     * @author 开发者（zzz）
     * @url /article/article/pickDown
     * @method *
     *
     * @param name:token require:1 default: desc:token
     *
     * @param name:id type:Int require:1 default:0 other: desc:id
     *
     *
     * @return id:id
     *
     */
    public function pickDown (){
        $input=input();
        //模块 - 输入数据
        $input['id'] = Request::param('id/d');

        // input结果返回
        $msg['data']['id'] = $input['id'];

        //模块 - 验证器
        $articleValidate = new \app\article\validate\Article;
        $validate = $articleValidate->scene('only_id')->check($input);
        if (!$validate) {
            $msg['msg'] = '验证失败';
            $msg['validate'] = $articleValidate->getError();
            return $this->errorJson($msg);
        }

        $user =  getIdByToken($input['token']);//通过token获取用户id
        if(count($user->all())>0){
            $msg['data']['creater']  = $input['creater'] = $user->all()['0']['account_id'];
            $msg['data']['updater']  = $input['updater'] = $user->all()['0']['account_id'];
        }else{
            $msg['msg'] = '无法获取用户数据！';
            return $this->errorJson($msg);
        }

        // ---	模块 - 查询  ---
        //查询条件
        $temp_map = [
            ['id','=',$input['id']],
        ];
        //去除为空的条件
        $find_map = [];
        foreach ($temp_map as $k=>$v){
            if ($v[2]===null || $v[2]=='' || $v[2]=='%%'){
                continue;
            }
            array_push($find_map,$v);
        }

        //获取数据
        $select_res = Db::name('Article')->where($find_map)->find();
        if($select_res!=null){//如果文章不存在
            $pick_map = [
                ['article_id','=',$input['id']],
                ['creater','=',$input['creater']],
                ['status','=',1]
            ];
            $pick_result = Db::name('pick')->where($pick_map)->find();//根据用户id和创建者
            if($pick_result!=null) {//如果点赞表里已存在，则进行取消点赞操作
                $views = $select_res['pick_count'] - 1;
                $select_res['pick_count'] = $views;
                $result = Db::name('Article')->where($find_map)->update($select_res);
                if ($result > 0) {//更新后，修改点赞表状态为不可用
                    $pick_result['status'] = 0;
                    Db::name('pick')->update($pick_result);
                }
            }else{
                $msg['msg'] = '您未点赞，请刷新后重新操作！';
                return $this->errorJson($msg);
            }
        }
        // find 返回数据
        $msg['data'] = $select_res;
        //接口输出json数据
        $msg['msg'] = '操作成功！';
        return $this->successJson($msg);
    }
}
